﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Viewer.Base.Config;
using System.Data;
using Ext.Net;
using Microsoft.Reporting.WebForms;

namespace Viewer.NhanSu.Reporting
{
    public partial class RptKhac : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadDataComboboxLoai();
            }
        }
        [DirectMethod]
        public void btnGenerate_Click()
        {
            string reportPath = string.Empty;
            if (string.IsNullOrEmpty(txtToChuc.Text))
            {
                hdTochucID.Text = string.Empty;
            }
            string toChucId = !string.IsNullOrEmpty(hdTochucID.Text) ? hdTochucID.Text : string.Empty;

            // Configuration setting from Reports.config
            // Path for Server Report

            if (hdReportType.Value.Equals("0"))
            {
                reportPath = ViewerConstant.NameReport.NSDaoTao;
            }
            else if (hdReportType.Value.Equals("1"))
            {
                reportPath = ViewerConstant.NameReport.NSKhenThuong;
            }
            else if (hdReportType.Value.Equals("2"))
            {
                reportPath = ViewerConstant.NameReport.NSKiLuat;
            }

            string strParameter = string.Format("{0},{1},{2},{3}", reportPath, txtToChuc.Text, hdTochucID.Value.ToString(), cbbYear.Text);
            UCReporting.LoadReport(strParameter);

            PnlSearch.Hidden = false;
           
        }
        [DirectMethod]
        public void btnReset_Click()
        {
            txtToChuc.Text = string.Empty;
            hdTochucID.Text = string.Empty;
            //Load lại data cho tree 
            cbbYear.Clear();           
            PnlSearch.Hidden = false;
        }
        /// <summary>
        /// Load data cho commbox năm theo xml
        /// </summary>
        private void LoadDataComboboxLoai()
        {
            string xmlFile = Server.MapPath(ViewerConstant.FILEPATH_Report_XML);

            DataSet ds = new DataSet();
            ds.ReadXml(xmlFile);
            storeNam.DataSource = ds.Tables["Nam"];
            storeNam.DataBind();
        }

        [DirectMethod]
        public void ShowPopUp()
        {
            UcToChuc.ShowLookUp_ToChuc("", true, "");
        }
        [DirectMethod]
        public void SetHidden(bool check)
        {
            PnlSearch.Hidden = check;
            btnReset_Click();
        }     
        [DirectMethod]
        public void SetPopUp()
        {         
            PnlSearch.Hidden = true;
        }
    }
}